package com.mxy.myapplication.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mxy.myapplication.R;
import com.mxy.myapplication.adapter.AdapterForRv_Waterfall;
import com.mxy.myapplication.util.LinearLayoutColorDivider;

/**
 * ViewPager上的碎片  瀑布布局
 */

public class FragmentOfViewPager_Waterfall extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.fragment, container, false);
        RecyclerView rv = (RecyclerView) v.findViewById(R.id.rv);

        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,
                StaggeredGridLayoutManager.VERTICAL);

        rv.setLayoutManager(staggeredGridLayoutManager);
        rv.setItemAnimator(new DefaultItemAnimator());
        rv.addItemDecoration(new LinearLayoutColorDivider(getActivity().getResources(),
                android.R.color.transparent, R.dimen.dip0, LinearLayoutManager.VERTICAL));
        AdapterForRv_Waterfall adapter = new AdapterForRv_Waterfall(this.getActivity(),
                staggeredGridLayoutManager);
        rv.setAdapter(adapter);

        return v;
    }
}